<?php
/**
 * Created by EPP.
 * User: yuxun
 * Date: 18/6/26
 * Time: 21:21
 */

class ModPacketNum extends Model {

    protected $table = 'packet_num';

    // 表名
    public function tableName(){
        return $this->table;
    }

    public static function model($className=__CLASS__){
        return parent::model($className);
    }

    public function getDbConnection(){
        return Yii::app()->dbOss;
    }

    public function select($params){
        $where  = ' WHERE p.game=:game ';
        $args   = array(
            ':game'     => $params['g']
        );

        if(!empty($params['number'])){
            $where .= ' AND p.number LIKE :number ';
            $args[':number'] = '%'.$params['number'].'%';
        }

        if(!empty($params['channel_id']) && $params['channel_id'] != 0){
            $where .= ' AND p.channel_id = :channel_id ';
            $args[':channel_id'] = $params['channel_id'];
        }

        $sql = "SELECT p.*,c.channel_name FROM {$this->table} as p inner join channel as c on p.channel_id = c.id {$where} ORDER BY create_time DESC";
        
        
        $result = $this->getDbConnection()->getAll($sql, $args);
        return $result;
    }
} 